//
//  FtTabBarViewController.m
//  Feast
//
//  Created by 胡光健 on 2017/8/23.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "FtTabBarViewController.h"
#import "FtNaviViewController.h"
#import "FtTabBar.h"
#import "FtToApplyForBusinessViewController.h"
#import "FtHomeViewController.h"

@interface FtTabBarViewController ()<tabBarDelegate>
@property(nonatomic,weak) UIButton * leftBarButton;
@property(nonatomic,weak) UIButton * rightBarButton;
@end

@implementation FtTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [UINavigationBar appearance];
    self.tabBar.backgroundColor = HJMainColor;
    self.tabBar.viewForFirstBaselineLayout.backgroundColor = HJColorRGB(255);

//    FtTabBar *tabBar = [[FtTabBar alloc] init];
//    tabBar.delegate = self;
////    tabBar.translu
//    //取消tabBar的透明效果
//    tabBar.translucent = YES;
//    [self setValue:tabBar forKey:@"tabBar"];

    // 首页
    FtHomeViewController * homeVC = [[FtHomeViewController alloc]init];
    [self addChildVc:homeVC title:@"首页" image:@"Shape-1" selectedImage:@"首页"];
    // 商家
    FtToApplyForBusinessViewController * toApplyVC = [[FtToApplyForBusinessViewController alloc]init];
    [self addChildVc:toApplyVC title:@"商家中心" image:@"商家" selectedImage:@"商家-1"];

}

- (void)addChildVc:(UIViewController *)childVc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage {
    // 先给外面传进来的小控制器 包装 一个导航控制器
    FtNaviViewController *nav = [[FtNaviViewController alloc] initWithRootViewController:childVc];
    nav.tabBarController.tabBar.backgroundColor = HJColorRGB(255);
    childVc.navigationItem.title = title;
    // 设置子控制器的文字
    childVc.tabBarItem.title = title; // 设置tabbar的文字
    
    // 设置子控制器的图片
    if (iOS7) {
        childVc.tabBarItem.image = [[UIImage imageNamed:image] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        childVc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    } else {
        childVc.tabBarItem.image = [UIImage imageNamed:image];
        childVc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
    }
    childVc.tabBarItem.imageInsets = UIEdgeInsetsMake(0, 0, 0, 0);
    // 设置文字的样式
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] = HJColorRGB(168);
    textAttrs[NSFontAttributeName] = HJFontSize(13);
    NSMutableDictionary *selectTextAttrs = [NSMutableDictionary dictionary];
    selectTextAttrs[NSForegroundColorAttributeName] = HJMainColor;
    selectTextAttrs[NSFontAttributeName] = HJFontSize(13);
    [nav.tabBarItem setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
    [nav.tabBarItem setTitleTextAttributes:selectTextAttrs forState:UIControlStateSelected];
    // 添加为子控制器
    [self addChildViewController:nav];
}
@end
